package com.qf.controller;

import com.qf.pojo.Product;
import com.qf.service.ProductService;
import com.qf.service.impl.ProductServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

/**
 *展示门户信息的servlet后端地址
 */
@WebServlet("/index")
public class IndexServlet extends BaseServlet {



    public void index(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        System.out.println("IndexServlet执行了") ;

        //获取到最新商品列表数据
        ProductService productService = new ProductServiceImpl() ;
        List<Product> newProducts = productService.getNewProducts();
        List<Product> hotProducts = productService.getHotProducts();
        if(newProducts!=null && hotProducts!=null){
            //存储在request域中
            request.setAttribute("newProducts",newProducts);
            request.setAttribute("hotProducts",hotProducts);
        }

        //请求转发/jsp/index.jsp
        request.getRequestDispatcher("/jsp/index.jsp").forward(request,response);
    }

}
